The user has selected some entries in the archive and decided to delete
them, so let's get rid of them.
1dodelete:
2 lister set handle busy on
3 lister query handle selentries
4 allents = result
5 call getall
6 if entries = 0 then
7 return
8
9 lister query handle numselfiles
10 nfiles = result
11 lister query handle numseldirs
12 ndirs = result
13 call dorequest('"'getcatstr(5,'Warning: you cannot get back'lf||,
14 'what you delete! OK to delete:'lf||lf'%s file(s) and'lf||,
15 '%s drawer(s) (and their contents)?',nfiles,ndirs)'"',
16 getcatstr(6,'Proceed|Cancel'))
17 if ~rc then
18 return
19
20 lister set handle title getcatstr(7,'Deleting from archive...')
21 lister refresh handle full
22
23 select
24 when arctype = 'LHA' then do
25 call open('actionfile','T:actionfile'handle,'w')
26 do i = 1 to entries
27 if type.i > 0 then
28 wild = '/#?'
29 else
30 wild = ''
31 call writeln('actionfile','"'patch(arcsubdir||name.i,1)||wild'"')
32 end
33 call close('actionfile')
34 address command 'LhA d -q -X -Qp -Qo "'patch(arcfile,0)'" @T:actionfile'handle
35 problem = rc > 0
36 address command 'Delete >NIL: T:LhA_ArcWork.#? QUIET'
37 problem = problem | rc = 0
38 call delete('T:actionfile'handle)
39 end
40 when arctype = 'LZX' then do
41 lzxcmd = 'LZX d -q -X0 --' lzxkludge(patch(arcfile,0))
42 linelen = 0
43 n = 0
44 do i = 1 to entries
45 if type.i > 0 then
46 wild = '/#?'
47 else
48 wild = ''
49 dothis = lzxkludge(patch(arcsubdir||name.i,0)||wild)
50 linelen = linelen + length(dothis) + 1
51 if i = 1 | linelen > 255 then do
52 n = n + 1
53 dothese.n = dothis
54 linelen = length(lzxcmd) + length(dothis) + 1
55 end
56 else
57 dothese.n = dothese.n dothis
58 end
59 do i = 1 to n
60 address command lzxcmd dothese.i
61 problem = rc > 0
62 if problem then
63 leave
64 end
65 end
66 end
67
68 if problem then
69 call displayerror(getcatstr(8,'Error while deleting from archive.'))
70 else do
71 call delete('T:ArcDir.list'handle)
72 do i = 1 to entries
73 if name.i = '' then do
74 lister query handle separate
75 if result = 'filesfirst' then do
76 lister query handle numfiles
77 entryno = result
78 end
79 else
80 entryno = 0
81 lister remove handle '#'entryno
82 end
83 else
84 lister remove handle '"'name.i'"'
85 end
86 end
87
88 lister set handle title 'ArcDir:' arcname
89 lister refresh handle full
90 return
Line:
1 Sub-routine label.
2 Set the lister state to busy so the user can't play around with it.
3 - 7 Get the list of selected entries and assign allents to it, then call
the getall routine to separate them into individual file/dir names.
If there weren't any entries selected then return.
9 - 18 Get the number of selected files and the number of selected
directories then tell the user he's about to delete so many of each
via the dorequest routine translating via the getcatstr routine
if necessary. If he chose Cancel then return.
20 - 21 Change the lister titlebar to inform the user what we're about to do,
and refresh the lister display so that he sees it.
23 - 66 The type of archive will select which block of statements in the
Select...When conditional block we execute. For this particular
example I'll assume it's a LhA archive because it's easier.
25 We open a file in T: for writing to, it will contain the entries that
we want to delete.
26 - 32 A DO loop in which we check the TYPE of the entry, (as detected in
the getall routine), if it's a directory we set wild to '#?',
if not then we set it to an empty string. We then write the entry to
the temporary file in T:, patching the string for strange
characters and adding wild. Keep doing it until there are no more
entries to add.
33 Close the temporary file.
34 Call the archiver command to delete the entries from the archive,
telling it to use the list in the temporary file.
35 If it wasn't successful then problem will be set to 1.
36 Delete temporary output file.
37 If there was a problem with the archiver command or the delete
command, then problem will equal 1.
38 - 39 Delete the temporary action file in T: and exit the Select...When
block.
68 - 69 If there was a problem then tell the user using displayerror .
70 - 71 Otherwise, delete the archive contents list in T:, we'll need a new
one.
72 - 85 We enter a DO loop to remove the entries from the lister display.
If the entry has an empty string for a name then we check the lister
separation method, (files first, mixed or directories first). If
it's files first then we ask for the number of files in the display
and make the entry number equal to the total number, if not we make
it equal to 0.
Remember, an entry with an empty string for a name is assumed to be
a directory, so if the separation method is files first the first
directory entry will equal the number of files in the display (zero
numbering for entries). If the separation method is directories
first or mixed, then the entry with no name is going to be the very
first, hence entry number will equal 0.
We then use lister remove to remove that entry number.
If the entry had a name then we just use lister remove to remove
the entry with that name.
88 - 89 Set the lister titlebar back to it's normal display and refresh it so
that the user sees that the entries have gone.
90 Return.
|